<template>
  <view class="password-container">
    <view class="header">
      <view class="header-title">安全设置</view>
      <view class="header-desc">全方位保护您的账户安全</view>
    </view>

    <view class="cell-list">
      <view
        class="cell-item"
        v-for="item in cellList"
        :key="item.id"
        @click="handleCellClick(item)"
      >
        <view class="cell-icon">
          <!-- <Icon :name="item.icon" :class="item.iconClass" /> -->
        </view>
        <view class="cell-content">
          <view class="cell-title">{{ item.title }}</view>
          <view class="cell-desc">{{ item.desc }}</view>
        </view>
        <view class="cell-arrow">
          <!-- <Icon name="arrow-right" class="arrow-icon" /> -->
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref } from "vue";
import Taro from "@tarojs/taro";
import { Icon } from "@tarojs/components";
import { useUserStore } from "@/store/user";

// 初始化密码 0-没有 1-有
const isPassword = useUserStore().userInfo.password;
console.log("----", isPassword);

// 单元格数据
const cellList = ref([
  {
    id: 1,
    title: "初始化登录密码",
    desc: "设置6-20位登录密码",
    icon: "lock",
    iconClass: "icon-lock",
    path: {
      login: "/pages-detail/mine/password/modify/loginPassword",
      register: "/pages-detail/mine/password/modify/registerPassword",
    },
  },
  {
    id: 2,
    title: "初始化支付密码",
    desc: "设置6位数字交易密码",
    icon: "credit-card",
    iconClass: "icon-credit-card",
    path: "/pages-detail/mine/password/modify/payment",
  },
  {
    id: 3,
    title: "初始化推荐码",
    desc: "更新您的推荐码信息",
    icon: "share-alt",
    iconClass: "icon-share-alt",
    path: "/pages-detail/mine/password/modify/code",
  },
]);

if (isPassword != 0) {
  cellList.value[0].title = "修改登录密码";
} else {
  cellList.value[0].title = "初始化登录密码";
}

// 处理单元格点击
const handleCellClick = (item) => {
  if (item.title == "修改登录密码") {
    Taro.navigateTo({
      url: item.path.login,
    });
  } else {
    Taro.navigateTo({
      url: item.path.register,
    });
  }

  // } else if(item.name === '修改支付密码') {
  //   Taro.navigateTo({
  //     url: '/pages-detail/mine/password/modify/modify-payment-password'
  //   });
  // } else if(item.name === '修改推荐码') {
  //   Taro.navigateTo({
  //     url: '/pages-detail/mine/password/modify/modify-referral-code'
  //   });
};
</script>

<style scoped>
.password-container {
  padding: 30rpx;
  background-color: #f5f5f5;
  min-height: 100vh;
  max-width: 100%;
}

.header {
  padding: 40rpx 0;
  text-align: center;
  margin-bottom: 30rpx;
  background: linear-gradient(135deg, #1a73e8, #4285f4);
  border-radius: 20rpx;
  color: white;
  box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.1);
}

.header-title {
  font-size: 38rpx;
  font-weight: bold;
  margin-bottom: 10rpx;
}

.header-desc {
  font-size: 24rpx;
  opacity: 0.9;
}

.cell-list {
  background-color: white;
  border-radius: 20rpx;
  overflow: hidden;
  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
}

.cell-item {
  display: flex;
  align-items: center;
  padding: 30rpx;
  border-bottom: 1rpx solid #f0f0f0;
  transition: all 0.3s ease;
}

.cell-item:last-child {
  border-bottom: none;
}

.cell-item:active {
  background-color: #f9f9f9;
  transform: scale(0.99);
}

.cell-icon {
  width: 52rpx;
  height: 52rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 24rpx;
  background-color: #e8f0fe;
  border-radius: 12rpx;
  box-shadow: 0 2rpx 6rpx rgba(26, 115, 232, 0.15);
}

.icon-lock {
  color: #1a73e8;
  font-size: 32rpx;
}

.icon-credit-card {
  color: #34a853;
  font-size: 32rpx;
}

.icon-share-alt {
  color: #fbbc05;
  font-size: 32rpx;
}

.cell-content {
  flex: 1;
}

.cell-title {
  font-size: 32rpx;
  font-weight: 500;
  color: #333;
}

.cell-desc {
  font-size: 24rpx;
  color: #666;
  margin-top: 6rpx;
}

.cell-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
}

.arrow-icon {
  color: #999;
  font-size: 28rpx;
  transition: transform 0.3s ease;
}

.cell-item:hover .arrow-icon {
  transform: translateX(6rpx);
}

/* H5适配 */
@media screen and (min-width: 768px) {
  .password-container {
    max-width: 600rpx;
    margin: 0 auto;
    padding: 40rpx;
  }

  .header {
    padding: 50rpx 0;
  }

  .cell-item {
    padding: 35rpx;
  }
}
</style>
